﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Practices.EnterpriseLibrary.Logging;

namespace CCF20Model
{
    public static class LoggerHelper
    {

        public static void LogZICDebug(string message)
        {
            Logger.Write(
                        new LogEntry
                        {
                            Categories = new[] { "ZICDebug" },
                            Message = message
                        });
        }
        
        public static void LogZICDebug(Fault f,string message)
        {
            Logger.Write(
                        new LogEntry
                        {
                            Categories = new[] { "ZICDebug" },
                            ExtendedProperties =
                                new Dictionary<string, object> 
                                { 
                                    { "FaultType", f.FaultType  }, 
                                    { "IDCSimNumber", f.IDCSimNumber  }, 
                                    { "VehicleID", string.Format("车辆ID:{0}",f.VehicleID??0)},
                                    { "AnchiID", string.Format("安驰ID:{0}",f.AnchiID)},
                                    { "HappenDate", string.Format("发生时间：{0}",f.HappenDate.ToShortDateString())  }, 
                                    { "Code", string.Format("故障码:{0}",f.Code??"")},
                                    { "CodeDescription", string.Format("故障描述:{0}",f.CodeDescription??"")}, 
                                    { "CodeVersion", string.Format("版本号:{0}",f.CodeVersion??-1)},
                                    { "CodeType", string.Format("智信通等级:{0}",f.CodeType)  }, 
                                    { "IsNormalFault", string.Format("是否常发故障:{0}",f.IsNormalFault)  }, 
                                    { "FaultInfo", string.Format("偶发信息:{0}",f.FaultInfo)  }, 
                                    { "Priority", string.Format("CCF等级:{0}",f.Priority)  }, 
                                    { "Mileage", string.Format("当前里程:{0}",f.CurrentMileage??-1)},
                                    { "CloseReason", f.CloseReason??""}
                                },
                            Message = message
                        });
        }
        public static void LogZICMonitorException(Exception ex)
        {
            LoggerHelper.LogZICMonitor(string.Format("[Exception:]{0} \t [Stack:] {1}",
                    ex.Message,
                    ex.StackTrace ?? ""));
            if (ex.InnerException != null)
            {
                LoggerHelper.LogZICMonitor(string.Format("[Inner Exception:]{0} \t [Stack:] {1}",
                        ex.InnerException.Message,
                        ex.InnerException.StackTrace ?? ""));
            }
        }
        public static void LogZICMonitor(string message)
        {
            Logger.Write(
                        new LogEntry
                        {
                            Categories = new[] { "ZICMonitor" },
                            Message = message
                        });
        }
        public static void LogCCF20(string message)
        {
            Logger.Write(
                        new LogEntry
                        {
                            Categories = new[] { "CCF20Log" },
                            Message = message
                        });
        }
        public static void FlushLog()
        {
            Logger.Reset();
        }

    }
}
